

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zhstyle}

\RequirePackage{mathtools,empheq}

%正体
\newcommand{\R}{\symbf{R}}
\newcommand{\Z}{\symbf{Z}}
\newcommand{\N}{\symbf{N}}
\newcommand{\Q}{\symbf{Q}}
\newcommand{\C}{\symbf{C}}
\renewcommand{\i}{\mathrm{i}}
\newcommand{\e}{\mathrm{e}}


%根指数位置的调整
\makeatletter

\newdimen\sqrtminh
\newdimen\sqrtmaxh
\sqrtminh=12.4pt
\sqrtmaxh=36.4pt
\newcount\rootpianyi

\def\r@@t#1#2{\setboxz@h{$\m@th#1\sqrtsign{#2}$}%
	%
	\dimen@\ht\z@\advance\dimen@\dp\z@
	\ifdim\dimen@>\sqrtminh
	\ifdim\dimen@<\sqrtmaxh
	\rootpianyi=3
	\fi\fi
	%
	\dimen@\ht\z@\advance\dimen@-\ht\rootbox
	\setbox\@ne\hbox{$\m@th#1\mskip\uproot@ mu$}%
	\advance\dimen@ by1.667\wd\@ne
	\mkern-\leftroot@ mu\mkern0mu
	\mkern\rootpianyi mu
	\raise\dimen@\copy\rootbox
	\mkern-\rootpianyi mu
    \mkern-5mu\mkern\leftroot@ mu
	\boxz@}

\makeatother



%%%定界符调整
\RequirePackage{mleftright}
\let\left\mleft
\let\right\mright
%定界符与文本基线对齐
\newcommand\leftright[4][\displaystyle]{
	\setbox0=\hbox{$#1#3$}
	\setbox2=\hbox{$\vcenter{\copy0}$}
	\raisebox{\dimexpr\ht0 -\ht2}{$#1\mleft#2\copy2\mright#4$}}
\def\bleft#1#2\bright#3{\leftright{#1}{#2}{#3}}
%定界符与文本居中对齐
\newcommand\cleftright[4][\displaystyle]{
	\setbox0=\hbox{$#1#3$}
	\setbox2=\hbox{$\vcenter{\copy0}$}
	\raisebox{0pt}{$#1\mleft#2\copy2\mright#4$}}
\def\cleft #1#2\cright #3{\cleftright{#1}{#2}{#3}}

%分数线延长
\makeatletter
\DeclareRobustCommand{\frac}[2]{\mathchoice{\displaystyle{\begingroup\mkern1mu#1\mkern1mu\endgroup\@@over\mkern1mu#2\mkern1mu}}%
	{\displaystyle{\begingroup\mkern1mu#1\mkern1mu\endgroup\@@over\mkern1mu#2\mkern1mu}}%
	{\begingroup\mkern1mu#1\mkern1mu\endgroup\@@over\mkern1mu#2\mkern1mu}%
	{\begingroup\mkern1mu#1\mkern1mu\endgroup\@@over\mkern1mu#2\mkern1mu}}%
\makeatother


%%%集合
\providecommand\cvert{}
\newcommand\SetSymbol[1][]{%
	\nonscript\:#1\vert
	\allowbreak
	\nonscript\:
	\mathopen {}}
\DeclarePairedDelimiterX\set[1]\{\}{%
	\renewcommand\cvert{\SetSymbol[\delimsize]}
	#1
}
%绝对值
\DeclarePairedDelimiterX{\abs}[1]{\lvert}{\rvert}{#1}
%上划线
\renewcommand{\bar}[1]{\,\overline{\!{#1}}}
\renewcommand{\overbar}[1]{\mskip.5\thinmuskip\overline{\mskip-.5\thinmuskip {#1} \mskip-.5\thinmuskip}\mskip.5\thinmuskip}

%带圈数字
\def\quan#1{\symbol{\numexpr"245F+#1\relax}}
\def\hquan#1{\symbol{\numexpr"100AF+#1\relax}}
\def\fquan#1{\symbol{\numexpr"1011F+#1\relax}}
\def\hfquan#1{\symbol{\numexpr"10190+#1\relax}}
\def\rquan#1{\symbol{\numexpr"10200+#1\relax}}
\def\hrquan#1{\symbol{\numexpr"10270+#1\relax}}
\RequirePackage{etoolbox}
\robustify{\quan}
\robustify{\hquan}
\robustify{\fquan}
\robustify{\hfquan}
\robustify{\rquan}
\robustify{\hrquan}

%罗马数字
\def\romannum#1{\symbol{\numexpr"216F+#1\relax}}
\def\Romannum#1{\symbol{\numexpr"215F+#1\relax}}
\def\roman#1{\romannum{\the\value{#1}}}
\def\Roman#1{\Romannum{\the\value{#1}}}

%导引点
\RequirePackage{tikz}

\RequirePackage{xpatch}
\usetikzlibrary{tikzmark,decorations.markings}
\tikzset{zhuangding/.style={
		decoration={markings,
			mark=between positions 0 and 1 step 4.5pt with
			{\node[]{\large$\cdot$};},
		},%postaction={decorate}
	}
}
%%%自定义公式导引线
%%%自定义公式导引线
\makeatletter
\def\maketag@@@#1{\hbox{%
		\m@th\normalfont
		\ifmeasuring@
		\expandafter\@gobble
		\else
		\expandafter\@firstofone
		\fi
		{%
			\PackageWarning{dot}{maketag: \the\value{eqn@dotfill}}%
			\tikzmark{\the\c@eqn@dotfill-1}%
			\iftikzmark{\the\c@eqn@dotfill}{%
				\tikz[remember picture, overlay]
				\draw [decorate,zhuangding] ([xshift=-5.7pt,yshift=2.7pt]pic cs:\the\c@eqn@dotfill-1) -- ([xshift=4pt,yshift=2.7pt]pic cs:\the\c@eqn@dotfill);%
			}{}%
		}%
		#1}}

\newcounter{eqn@dotfill}
\newcommand\markDotfill{%
	\ifmeasuring@
	\expandafter\@gobble
	\else
	\expandafter\@firstofone
	\fi
	{%
		\addtocounter{eqn@dotfill}{3}%
		% \PackageWarning{dot}{markdotfill: \the\value{eqn@dotfill}}%
		\tikzmark{\the\c@eqn@dotfill}%
	}%
}

% step \c@eqn@dotfill per equation line
% TODO: check every occurrence where counter "equation" is modified (a possible linebreak)
\xpatchcmd\incr@eqnum
{\refstepcounter{equation}}
{\refstepcounter{equation}\stepcounter{eqn@dotfill}}
{}{\fail}

\def\maybe@execute#1{%
	\ifdefined#1%
	\expandafter#1
	\fi
}

\maybe@execute\MHInternalSyntaxOn
\xpatchcmd\nonumber
{\addtocounter{equation}\m@ne}
{\addtocounter{equation}\m@ne\stepcounter{eqn@dotfill}}
{}{\fail}
\maybe@execute\MHInternalSyntaxOff

%\xpatchcmd\nonumber
%  {\addtocounter{equation}\m@ne}
%  {\addtocounter{equation}\m@ne\stepcounter{eqn@dotfill}}
%  {}{\fail}

\xpatchcmd\subequations
{\refstepcounter{equation}}
{\refstepcounter{equation}\stepcounter{eqn@dotfill}}
{}{\fail}
\makeatother


%%%正文导引线重新设置更加美观
%\def\mydots{%
	%	\leavevmode\hspace{2pt}\xleaders\hbox to 4.5pt{\hfil{\large$\cdot$}\hfil}\hfill\kern3.5pt}

%%%正文导引线重新设置更加美观
\def\mydots{%
	\leavevmode\unskip\penalty9999\hspace{2pt}\xleaders\hbox  to 4.5pt{\hfil{\large$\cdot$}\hfil}\hfill\kern3.5pt}

\newcommand{\zhdots}[1]{\markDotfill\tag*{\text{#1}}}
\endinput



